package com.qfedu.fy.controller;

import com.qfedu.fy.entity.Department;
import com.qfedu.fy.entity.User;
import com.qfedu.fy.service.intf.DepartmentService;
import com.qfedu.fy.vo.PageBeanVo;
import com.qfedu.fy.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * ......................我佛慈悲......................
 * _oo0oo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * 0\  =  /0
 * ___/`---'\___
 * .' \\|     |// '.
 * / \\|||  :  |||// \
 * / _||||| -卍-|||||- \
 * |   | \\\  -  /// |   |
 * | \_|  ''\---/''  |_/ |
 * \  .-\__  '-'  ___/-. /
 * ___'. .'  /--.--\  `. .'___
 * ."" '<  `.___\_<|>_/___.' >' "".
 * | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 * \  \ `_.   \_ __\ /__ _/   .-` /  /
 * =====`-.____`.___ \_____/___.-`___.-'=====
 * `=---='
 * ..............佛祖保佑无BUG..................
 *
 * @author mxj
 * @date 2022/6/16 20:30
 */
@RestController
@RequestMapping("/api/department/")
public class DepartmentController {
    @Autowired
    private DepartmentService service;


    @PostMapping("save.do")
    public R save(Department department){
        return service.add(department);
    }

    @GetMapping("page.do")
    public PageBeanVo page(int page,int limit){
        return service.selectAll(page,limit);
    }

    @PostMapping("update.do")
    public R update(Department department){
        return service.update(department);
    }

    /**
     * 删除*/
    @PostMapping("del.do")
    public R del(int id){
        return service.del(id);
    }
    /**
     * 查询所有部门*/
    @GetMapping("all.do")
    public R all(){
        return service.all();
    }

    /**
     *生成Excel并下载 */
    @GetMapping("download.do")
    public void download(HttpServletResponse response) throws IOException {
        service.createExcel(response);
    }
    @PostMapping("upload.do")
    public R upload(MultipartFile file) throws IOException {
        return service.uploadExcel(file);
    }
    @GetMapping("nums.do")
    public R nums() {
        return service.selectNums();
}}
